class Person:
    def __init__(self,name,age):
        self.name = name
        self.age = age

    def __str__(self) -> str:
        return ("打印信息：print 自动调用")

    def sayHi(self):
        print('你好啊！ 我叫 %s' % self.name)

xiaoming = Person('小明',18)
xiaoming.sayHi()
print(xiaoming)


"""
私有属性 方法
"""

class Woman:
    def __init__(self,name) -> None:
        self.name = name
        self.__age = 18  # 私有属性
    def mimi(self):
        print('【%s】今年%d岁' % (self.name,self.__age))

xiaofang = Woman('小芳')
# xiaoming.__age  不能获取
xiaofang.mimi()


"""
继承
"""
class Animal:
    def eat(self):
       print("吃")
    def sleep(self):
        print("睡")

class Dog(Animal):
    def wang(self):
        print('旺旺')
    def eat(self): # 扩展父类的eat方法
        super().eat() # 调用父类Animal的eat方法
        print("啃骨头")
    def sleep(): # 重写父类的sleep方法
        print('狗不睡觉，要看门')

xiaohuang = Dog()
xiaohuang.eat()
xiaohuang.wang()



"""
多态
"""
class Pig(object):
    def __init__(self,name) -> None:
        self.name = name
    def game(self):
        print("%s 母猪上树" % self.name)

class BaJiePie(Pig):
    def game(self):
        print("%s 母猪飞天上树" % self.name)
    
class Person1(object):
    def __init__(self,name) -> None:
        self.name = name
    def gamePig(self,pig):
        print("%s 和 %s玩" % (self.name,pig.name))
        pig.game()

# pig = Pig("佩奇")
pig = BaJiePie("八戒")
xiaoxiao = Person1("晓晓")
xiaoxiao.gamePig(pig)